/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            myHousekeepingDispatchInfo: {
                pools: [],
                total: 0,
                records: 1,
                moreCondition: false,
                repairName: '',
                currentRepairId: '',
                states: [],
                conditions: {
                    cartId: '',
                    applyName: '',
                    applyTel: '',
                    repairType: '',
                    roomId: '',
                    roomName: '',
                    ownerId: '',
                    state: ''
                }
            }
        },
        _initMethod: function () {
            vc.getDict('housekeeping_serv_pool', "state", function (_data) {
                $that.myHousekeepingDispatchInfo.states = _data;
            });
            $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('myHousekeepingDispatch', 'listOwnerRepair', function (_param) {
                $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingPools(_currentPage, DEFAULT_ROWS);
            });
            vc.on('myHousekeepingDispatch', 'notifyData', function (_param) {
                $that._closeRepairDispatchOrder(_param);
            });
        },
        methods: {
            _listHousekeepingPools: function (_page, _rows) {
                $that.myHousekeepingDispatchInfo.conditions.page = _page;
                $that.myHousekeepingDispatchInfo.conditions.row = _rows;
                $that.myHousekeepingDispatchInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                var param = {
                    params: $that.myHousekeepingDispatchInfo.conditions
                };
                param.params.cartId = param.params.cartId.trim();
                param.params.applyName = param.params.applyName.trim();
                param.params.applyTel = param.params.applyTel.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingServPool/queryStaffFinishServ',
                    param,
                    function (json, res) {
                        var _myHousekeepingDispatchInfo = JSON.parse(json);
                        $that.myHousekeepingDispatchInfo.total = _myHousekeepingDispatchInfo.total;
                        $that.myHousekeepingDispatchInfo.records = _myHousekeepingDispatchInfo.records;
                        $that.myHousekeepingDispatchInfo.pools = _myHousekeepingDispatchInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.myHousekeepingDispatchInfo.records,
                            dataCount: $that.myHousekeepingDispatchInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _moreCondition: function () {
                if ($that.myHousekeepingDispatchInfo.moreCondition) {
                    $that.myHousekeepingDispatchInfo.moreCondition = false;
                } else {
                    $that.myHousekeepingDispatchInfo.moreCondition = true;
                }
            },
            _openDetail: function (_pool) {
                vc.jumpToPage('/#/pages/goods/housekeepingServDetail?poolId=' + _pool.poolId)
            },
            _closeRepairDispatchOrder: function (_orderInfo) {
                var _repairDispatchParam = {
                    repairId: $that.myHousekeepingDispatchInfo.currentRepairId,
                    context: _orderInfo.remark,
                    communityId: vc.getCurrentCommunity().communityId
                };
                if (_orderInfo.state == '1100') {
                    _repairDispatchParam.state = '10002';
                } else {
                    _repairDispatchParam.state = '10003';
                }
                vc.http.post(
                    'myHousekeepingDispatch',
                    'closeOrder',
                    JSON.stringify(_repairDispatchParam),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        if (res.status == 200) {
                            //关闭model
                            $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
                            return;
                        }
                        vc.toast(json);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _openDispatchRepairDetail: function (_ownerRepair) {
                vc.emit('ownerRepairDetail', 'openOwnerRepairDetailModal', _ownerRepair);
            },
            //查询
            _queryHousekeepingPoolMethod: function () {
                $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetHousekeepingPoolMethod: function () {
                $that.myHousekeepingDispatchInfo.conditions.cartId = "";
                $that.myHousekeepingDispatchInfo.conditions.applyName = "";
                $that.myHousekeepingDispatchInfo.conditions.applyTel = "";
                $that.myHousekeepingDispatchInfo.conditions.state = "";
                $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
            }
        }
    });
})(window.vc);
